//index.js
//获取应用实例
const app = getApp()
import api from '../../utils/api.js'
import regeneratorRuntime from '../../utils/regenerator-runtime/runtime-module.js'
Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    userInfo: {},
    dynamic: []
  },
  async onLoad (options) {
    if (options.id){
      wx.setStorageSync('shareId', options.id)
    }
    let notice = await api.authRequest("/moonCakeBetting/active?include=user")
    this.setData({
      dynamic: notice.data.data
    })
  },
  
  onGotUserInfo: async function (e) {
    if (await api.checkLogin()) {
        wx.navigateTo({
          url: '/pages/game/game',
        })
    } else {
      wx.getSetting({
        success: async res => {
          if (res.authSetting['scope.userInfo']) {
            let authResponse = await api.login()
          }
        }
      })
    }
  },
  onGotUserInfo_1: async function (e) {
    if (await api.checkLogin()) {
      let user = await api.authRequest("/user")
      wx.setStorageSync('user', user.data)
      this.userInfo = user.data
      if (this.userInfo) {
        wx.navigateTo({
          url: '/pages/prize/prize',
        })
      }
    } else {
      wx.getSetting({
        success: async res => {
          if (res.authSetting['scope.userInfo']) {
            let authResponse = await api.login()
          }
        }
      })
    }
  }
  })
